<template>
	<view>
		
		<!-- 第三方登录 -->
		<view class="other-login u-f-ajc">
			<block v-for="(item, index) in providerList" :key="index">
				<view class="u-f-ajc u-f1" @tap="tologin(item)">
					<view class="icon iconfont u-f-ajc" :class="['icon-' + item.icon]"></view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				providerList: []
			}
		},
		created() {
			this.getLoginAuth();
		},
		methods:{
			// 获取当前登录方式
			getLoginAuth(){
				uni.getProvider({
					service: 'oauth',
					success: (result) => {
						this.providerList = result.provider.map((value) => {
							let providerName = '';
							let icon = '';
							switch (value) {
								case 'weixin':
									providerName = '微信登录';
									icon = 'weixin';
									break;
								case 'qq':
									providerName = 'QQ登录';
									icon = 'QQ';
									break;
								case 'sinaweibo':
									providerName = '新浪微博登录';
									icon = 'xinlangweibo';
									break;
								case 'alipay':
									providerName = '支付宝登录'
									icon = '';
									break;
							}
							return {
								name: providerName,
								id: value,
								icon: icon
							}
						});
						
					},
					fail: (error) => {
						console.log('获取登录通道失败', error);
					}
				})
			},
			tologin(provider) {
				uni.login({
					provider: provider.id,
					// #ifdef MP-ALIPAY
					scopes: 'auth_user', //支付宝小程序需设置授权类型
					// #endif
					success: (res) => {
						console.log('login success:', res);
						// 更新保存在 store 中的登录状态
					},
					fail: (err) => {
						console.log('login fail:', err);
					}
				});
			}
			
		}
	}
</script>

<style scoped>
	.other-login{
		padding: 20upx 80upx;
	}
	.other-login>view>view{
		width: 100upx;
		height: 100upx;
		border-radius: 100%;
		font-size: 55upx;
		color: #FFFFFF;
	}
	.icon-weixin{
		background: #2BD19B;
	}
	.icon-xinlangweibo{
		background: #2CAEFC;
	}
	.icon-QQ{
		background: #FC7729;
	}
</style>
